package com.tools.Fisco_tools;

import com.common.LO.UserInformationLO;
import com.tools.Fisco.UserInfo;
import lombok.extern.slf4j.Slf4j;
import org.fisco.bcos.sdk.abi.datatypes.generated.Int256;
import org.fisco.bcos.sdk.model.TransactionReceipt;
import org.fisco.bcos.sdk.transaction.model.exception.ContractException;

import java.math.BigInteger;
@Slf4j
public class UserInfo_tools {
   public static String insert(UserInfo userInfo, UserInformationLO userInformationLO) throws ContractException {

       BigInteger Balance = new BigInteger( String.valueOf(userInformationLO.getBalance()));
       BigInteger Account_status = new BigInteger(String.valueOf(userInformationLO.getAccountStatus()));
       BigInteger Account_role = new BigInteger(String.valueOf(userInformationLO.getAccountRole()));
       log.info("create fisco sdk");
       UserInfo.Struct0 insert  = new UserInfo.Struct0(
               userInformationLO.getId(),
               userInformationLO.getAccount(),
               userInformationLO.getPassword(),
               userInformationLO.getPayPassword(),
               Balance,
               Account_status,
               Account_role,
               userInformationLO.getName(),
               userInformationLO.getUsername(),
               userInformationLO.getPhone(),
               userInformationLO.getCard(),
               userInformationLO.getCreateDate().toString(),
               userInformationLO.getUpdateDate().toString()
      );
       TransactionReceipt insert1 = userInfo.insert(insert);
       return insert1.getTransactionHash();
   }
    public static UserInfo.Struct0 select(UserInfo userInfo,String id) throws ContractException {
        UserInfo.Struct0 select = userInfo.select(id);
        return select;
    }
    public static String update (UserInfo userInfo, UserInformationLO userInformationLO){
        BigInteger Balance = new BigInteger( String.valueOf(userInformationLO.getBalance()));
        BigInteger Account_status = new BigInteger(String.valueOf(userInformationLO.getAccountStatus()));
        BigInteger Account_role = new BigInteger(String.valueOf(userInformationLO.getAccountRole()));
        UserInfo.Struct0 insert  = new UserInfo.Struct0(
                userInformationLO.getId(),
                userInformationLO.getAccount(),
                userInformationLO.getPassword(),
                userInformationLO.getPayPassword(),
                Balance,
                Account_status,
                Account_role,
                userInformationLO.getName(),
                userInformationLO.getUsername(),
                userInformationLO.getPhone(),
                userInformationLO.getCard(),
                userInformationLO.getCreateDate().toString(),
                userInformationLO.getUpdateDate().toString()
        );
        TransactionReceipt update = userInfo.update(insert);
        return  update.getTransactionHash();
    }
}
